var spiralOrder = function(matrix) {
    if (matrix.length === 0) {
        return []
    }
    let rotateNum = Math.floor(Math.min(matrix.length, matrix[0].length) / 2)
    let forNum = Math.min(matrix.length, matrix[0].length) % 2 === 0 ? rotateNum : rotateNum + 1;
    let lenCol = matrix[0].length
    let lenRow = matrix.length
    let rsl = []
    for (let i = 0; i < forNum; i++) {
        for (let j = i; j < lenCol - i; j++) {
            rsl.push(matrix[i][j])
        }
        for (let k = i + 1; k < lenRow - i - 1; k++) {
            rsl.push(matrix[k][lenCol - i - 1])
        }
        if (lenRow - i - 1 > i) {
            for (let t = lenCol - i - 1; t >= i; t--) {
                rsl.push(matrix[lenRow - i - 1][t])
            }
        }
        if (lenCol - i - 1 > i) {
            for (let k = lenRow - i - 1 - 1; k > i; k--) {
                rsl.push(matrix[k][i])
            }
        }

    }
    return rsl
};
console.log(spiralOrder([
    [7],
    [9],
    [6]
]))